<?php

use think\migration\Migrator;
use think\migration\db\Column;

class BasicCompany extends Migrator
{
    public function up()
    {
        $table = $this->table('basic_company');
        $table
            //step1:名称
            ->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '公司名称'])
            ->addColumn('short_name', 'string', ['limit' => 20, 'default' => '', 'comment' => '公司简称'])
            ->addColumn('license_number', 'string', ['limit' => 50, 'default' => '', 'comment' => '公司营业执照号码'])
            ->addColumn('license_number_simple', 'string', ['limit' => 4, 'default' => '', 'comment' => '公司营业执照号码-后四位用于工况）'])
            ->addColumn('realtime_company', 'integer', ['limit' => 1, 'default' => 0, 'comment' => '是否实时企业，0否1是'])

            //step2:行业名称
            ->addColumn('industry_id', 'string', ['limit' => 11, 'default' => '', 'comment' => '行业ID'])

            //step3:所在区域
            ->addColumn('region_id', 'integer', ['comment'=>'企业所属区域ID'])
            ->addColumn('address', 'string', ['limit' => '200', 'comment'=>'位置'])

            //step4:经纬度
            ->addColumn('longitude', 'string', ['limit' => 50, 'comment' => '经度'])
            ->addColumn('latitude', 'string', ['limit' => 50, 'comment' => '纬度'])

            //step5:动态时序网格相关
            ->addColumn('nrow', 'integer', ['comment'=>'所在网格的行'])
            ->addColumn('ncol', 'integer', ['comment'=>'所在网格的列'])
            ->addColumn('grid_repeat', 'integer', ['limit' => 1, 'comment'=>'1重复0不重复'])
            ->addColumn('grid_number', 'integer', ['limit' => 4, 'comment'=>'网格序号'])
            ->addColumn('grid_longitude', 'string', ['limit' => 20, 'comment'=>'网格纬度'])
            ->addColumn('grid_latitude', 'string', ['limit' => 20, 'comment'=>'网格纬度'])
            ->addColumn('grid_center_distance', 'string', ['limit' => 20, 'comment'=>'网格纬度'])

            //step6:备注
            ->addColumn('memo', 'string', ['comment'=>'备注'])
            ->addColumn('delete_time', 'integer', ['limit' => 11, 'default' => 0, 'comment'=>'软删除0正常'])


            //主键
            ->addIndex(['name'])

            //注释
            ->setComment('基本信息 - 公司名称')

            //引擎
            ->setEngine('InnoDB')
            ->save();
    }

    public function down()
    {
        $this->table('basic_company')->drop();
    }
}
